

use  "/home/mfa/allj/candeal/CDEAL_trades_pre1619_2_hour", clear 
rename time_stamp time_trade
drop hour_stamp N price
joinby cusip date using  coll_quotes_seconds_2019

sort cusip time_trade time_stamp bs

gen time_diff = time_trade - time_stamp 
drop if time_diff < 0 
bys cusip time_trade: egen min_time = min(time_diff)
sort cusip time_trade time_stamp bs
keep if min_time==time_diff

gen gap_buy = yield - askyield if bs=="BUY"
gen gap_sell = yield - bidyield if bs=="SELL"

gen gap = gap_buy if gap_buy!=.
replace gap = gap_sell if gap_sell!=.

replace bs="investor buys" if bs=="BUY"
replace bs="investor sells" if bs=="SELL"

gen time_diff_s = time_diff/(1000*60)

gr box gap if time_diff_s<10, over(bs)  ytitle("basis points")   graphregion(color(white)) yline(0,lpattern(dash)lcolor(black)) bar(1, fcolor(white) lcolor(black)) noout note("") ysc(range(-0.05 0.05)) ylab(-0.05 (0.01) 0.05)
gr export box_gap_seconds_billsandbonds_closest_w10s.pdf, as(pdf) replace
gr export box_gap_seconds_billsandbonds_closest_w10s.png, as(png) replace



